// 商品类别模型
let model = require('../db/carts');


// 写入购物车数据
let insert = async (obj) => {
  return model.insertMany(obj);
}


// 删除一条数据
let delOne = async (id) => {
  return model.deleteOne({ '_id': id })
}

// 删除多条
let delMany = async (obj) => {
  return model.deleteMany(obj);
}

// 修改购物数量
let updateNum = async (obj, n) => {
  return model.updateOne(obj, { $inc: { cartnum: n } })
}

// 修改勾选状态
let updateSelect = async (obj, sel) => {
  return model.updateMany(obj, { $set: { is_select: sel } })
}

// 根据uid和gid查找
let findBygIdAnduId = async (uid, gid) => {
  return model.find({ uid, gid })
}

// 根据uid查找
let findByuId = async (uid) => {
  return model.find({ uid })
}
// 根据id查找
let findCartById = async (id) => {
  return model.find({ '_id':id })
}



module.exports = {
  insert,
  findBygIdAnduId,
  updateNum,
  updateSelect,
  delOne,
  findByuId,
  delMany,
  findCartById
}